/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.config.MyProps;
import com.jeesite.modules.goods.entity.ZtCardOrder;
import com.jeesite.modules.goods.service.ZtCardOrderService;
import com.jeesite.modules.goods.service.ZtColorService;
import com.jeesite.modules.goods.service.ZtGoodsService;
import com.jeesite.modules.goods.service.ZtQuanselfService;
import com.jeesite.modules.goods.service.ZtSpecificationsService;
import com.jeesite.modules.sys.service.DictDataService;
import com.jeesite.modules.sys.service.UserService;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;

/**
 * 测试数据Controller
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/memOrder")
public class ZtCardOrderController extends BaseController {

	@Autowired
	private ZtCardOrderService ztCardOrderService;

	@Autowired
	private UserService userService;
	
	@Autowired
	private ZtColorService ztColorService;
	@Autowired
	private ZtSpecificationsService specificationsService;

	@Autowired
	private ZtGoodsService ztGoodsService;

	@Autowired
	private ZtQuanselfService ztQuanselfService;

	@Autowired
	private MyProps myProps;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ZtCardOrder get(String id, boolean isNewRecord) {
		ZtCardOrder ztCardOrder = new ZtCardOrder();
		if (StringUtils.isNotBlank(id)) {
			ztCardOrder.setId(id);
			ztCardOrder = ztCardOrderService.get(ztCardOrder);
		}
		if (ztCardOrder == null) {
			ztCardOrder = new ZtCardOrder();
		}
		return ztCardOrder;
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("ztCardOrder:ztCardOrderData:view")
	@RequestMapping(value = { "list", "" })
	public String list(ZtCardOrder ztCardOrder, Model model) {
		model.addAttribute("ztCardOrder", ztCardOrder);

		return "modules/ztCardOrder/ztCardOrderList";
	}

	/**
	 * 个人查询列表
	 */

	@RequestMapping(value = "listself")
	public String listself(ZtCardOrder ztCardOrder, Model model,HttpSession session) {
		
		if(ztCardOrder!=null && ztCardOrder.getZtAdmin()!=null && StringUtils.isNotBlank(ztCardOrder.getZtAdmin().getId())){
			session.setAttribute("ztCardOrderAdminid", ztCardOrder.getZtAdmin().getId());
		}else{
			if(ztCardOrder==null){ztCardOrder=new ZtCardOrder();}
			ZtAdmin ztAdmin=new ZtAdmin();
			ztAdmin.setId(session.getAttribute("ztCardOrderAdminid").toString());
			ztCardOrder.setZtAdmin(ztAdmin);
		}
		model.addAttribute("ztCardOrder", ztCardOrder);

		return "modules/ztCardOrder/ztCardOrderselfList";
	}
	
	/**
	 * 查询列表数据
	 */

	@RequestMapping(value = "listselfData")
	@ResponseBody
	public Page<ZtCardOrder> listselfData(ZtCardOrder ztCardOrder, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		
		Page<ZtCardOrder> page = ztCardOrderService.findPage(new Page<ZtCardOrder>(request,
				response), ztCardOrder);

		return page;
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ztCardOrder:ztCardOrderData:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ZtCardOrder> listData(ZtCardOrder ztCardOrder, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		
		Page<ZtCardOrder> page = ztCardOrderService.findPage(new Page<ZtCardOrder>(request,
				response), ztCardOrder);

		

		return page;
	}

	DictDataService dictDataService;

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ztCardOrder:ztCardOrderData:view")
	@RequestMapping(value = "form")
	public String form(@ModelAttribute("ztCardOrder") ZtCardOrder ztCardOrder, Model model,
			HttpServletRequest request, HttpServletResponse response) {
	
		model.addAttribute("ztCardOrder", ztCardOrder);
		

		return "modules/ztCardOrder/ztCardOrderForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("ztCardOrder:ztCardOrderData:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ZtCardOrder ztCardOrder) {

		ztCardOrderService.save(ztCardOrder);

		return renderResult(Global.TRUE, text("保存订单成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("ztCardOrder:ztCardOrderData:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ZtCardOrder ztCardOrder) {
		ztCardOrderService.delete(ztCardOrder);
		return renderResult(Global.TRUE, text("删除订单成功！"));
	}
}